<?php
require_once __DIR__.'/../vendor/autoload.php';

use Symfony\Component\HttpFoundation\JsonResponse;
use Predis\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;

$config = require './config.php';

$request = Request::createFromGlobals();
$session = new Session();
$session->start();
$request->setSession($session);

$key = $request->query->get('key', '');
$openId = $request->query->get('openid', '');

if ($key !== $config['stu_helper']['key']) {
    $response = new JsonResponse(['status' => 401, 'data' => ['error' => 'error key']]);
    $response->send();
    exit;
}

if ($openId === '') {
    $response = new JsonResponse(['status' => 400, 'data' => ['error' => 'need openid']]);
    $response->send();
    exit;
}
$redis = new Client($config['redis']);
$key = 'user:'.$openId;
$user = $redis->get($key);
$user = json_decode($user, true);
$response = new JsonResponse(['status' => 200, 'data' => $user]);
$response->send();
exit;
?>
